<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="vs" uri="/vseaf-tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <base href="<%=basePath%>">

    <title>Tree 加载方式</title>
    <link href="<%=basePath %>/xqfx/static/css/axure_rp_page.css" type="text/css" rel="stylesheet">
    <link href="<%=basePath %>/xqfx/static/css/styles_002.css" type="text/css" rel="stylesheet">
    <link href="<%=basePath %>/xqfx/static/css/styles.css" type="text/css" rel="stylesheet">
    <script type="text/javascript" charset="UTF-8" src="<%=basePath %>/xqfx/static/js/WdatePicker.js"></script>
    <link href="<%=basePath %>/xqfx/static/css/bootstrap.min.css" rel="stylesheet">
    <link href="<%=basePath %>/xqfx/static/css/bootstrap-theme.css" rel="stylesheet">
    <vs:base/>
</head>

<body>
<vs:form id="form1" isImValidation="true"  action="" method="post">
    <div id="u100" class="ax_动态面板" data-label="bzfl_tj">
        <div id="u100_state0" class="panel_state" data-label="State1">
            <div id="u100_state0_content" class="panel_state_content">

                <!-- Unnamed (Image) -->
                <div id="u101" class="ax_image">
                    <img id="u101_img" class="img " src="<%=basePath %>/xqfx/static/images/u103.png"/>
                    <!-- Unnamed () -->
                    <div id="u102" class="text">
                        <p><span style="font-family:'应用字体 Regular', '应用字体';">&nbsp;</span></p>
                    </div>
                </div>

                <!-- Unnamed (形状) -->
                <div id="u103" class="ax_文本段落">
                    <img id="u103_img" class="img " src="<%=basePath %>/xqfx/static/images/transparent.gif"/>
                    <!-- Unnamed () -->
                    <div id="u104" class="text">
                        <p><span style="font-family:'应用字体 Bold', '应用字体';">标</span><span style="font-family:'应用字体 Bold', '应用字体';">&nbsp;</span><span style="font-family:'应用字体 Bold', '应用字体';">准</span><span style="font-family:'应用字体 Bold', '应用字体';">&nbsp;</span><span style="font-family:'应用字体 Bold', '应用字体';">分</span><span style="font-family:'应用字体 Bold', '应用字体';">&nbsp;</span><span style="font-family:'应用字体 Bold', '应用字体';">类</span></p>
                    </div>
                </div>

                <!-- Unnamed (水平线) -->
                <div id="u105" class="ax_水平线">
                    <img id="u105_start" class="img " src="<%=basePath %>/xqfx/static/images/transparent.gif" alt="u105_start"/>
                    <img id="u105_end" class="img " src="<%=basePath %>/xqfx/static/images/transparent.gif" alt="u105_end"/>
                    <img id="u105_line" class="img " src="<%=basePath %>/xqfx/static/images/u105_line.png" alt="u105_line"/>
                </div>

                <!-- Unnamed (形状) -->
                 <table class="tjform" style="width:300px;margin-top:39px;margin-left: -65px;">
                    <tr>
                        <td colspan="4" align="center">
                            <button id="saveBtn" type="button" onclick="addBzxqfx()" class="btn btn-info" >
                                <span class="glyphicon glyphicon-ok" aria-hidden="true"></span> 保&nbsp;&nbsp;存
                            </button>
                            <button id="backBtn" type="button" class="btn btn-warning" onclick="back()">
                                <span class="glyphicon glyphicon-remove" aria-hidden="true"></span> 取&nbsp;&nbsp;消
                            </button>
                        </td>
                    </tr>
                </table>

                <!-- Unnamed (形状) -->
                <div id="u110" class="ax_文本段落">
                    <img id="u110_img" class="img " src="<%=basePath %>/xqfx/static/images/transparent.gif"/>
                    <!-- Unnamed () -->
                    <div id="u111" class="text">
                        <p><span style="font-family:'应用字体 Bold', '应用字体';">基本信息</span></p>
                    </div>
                </div>

                <!-- Unnamed (形状) -->
                <div id="u112" class="ax_形状">
                    <img id="u112_img" class="img " src="<%=basePath %>/xqfx/static/images/u112.png"/>
                    <!-- Unnamed () -->
                    <div id="u113" class="text">
                        <p><span style="font-family:'应用字体 Regular', '应用字体';">&nbsp;</span></p>
                    </div>
                </div>

                <!-- Unnamed (形状) -->
                <div id="u114" class="ax_文本段落">
                    <img id="u114_img" class="img " src="<%=basePath %>/xqfx/static/images/transparent.gif"/>
                    <!-- Unnamed () -->
                    <div id="u115" class="text">
                        <p><span style="font-family:'应用字体 Regular', '应用字体';color:#333333;">上级标准分类名称</span><span style="font-family:'应用字体 Regular', '应用字体';color:#FF0000;">*</span><span style="font-family:'应用字体 Regular', '应用字体';color:#333333;">：</span></p>
                    </div>
                </div>

                <!-- Unnamed (形状) -->
                <div id="u116" class="ax_形状">
                    <!-- Unnamed () -->
                    <div id="u117" class="text">
                        <input id="sjbzmc" style="width:140px;" readonly="true" validator="required"/>
                    </div>
                </div>

                <!-- Unnamed (形状) -->
                <div id="u118" class="ax_文本段落">
                    <img id="u118_img" class="img " src="<%=basePath %>/xqfx/static/images/transparent.gif"/>
                    <!-- Unnamed () -->
                    <div id="u119" class="text">
                        <p><span style="font-family:'应用字体 Regular', '应用字体';color:#333333;">标准分类名称</span><span style="font-family:'应用字体 Regular', '应用字体';color:#FF0000;">*</span><span style="font-family:'应用字体 Regular', '应用字体';color:#333333;">：</span></p>
                    </div>
                </div>

                <!-- Unnamed (文本框) -->
                <div id="u120" class="ax_文本框">
                    <input id="bzmc" type="text" value="" class="text_sketch" validator="required" maxlength="64"/>
                </div>

                <!-- Unnamed (形状) -->
                <div id="u121" class="ax_文本段落">
                    <img id="u121_img" class="img " src="<%=basePath %>/xqfx/static/images/transparent.gif"/>
                    <!-- Unnamed () -->
                    <div id="u122" class="text">
                        <p><span style="font-family:'应用字体 Regular', '应用字体';">标准分类</span><span style="font-family:'应用字体 Regular', '应用字体';">说明</span><span style="font-family:'应用字体 Regular', '应用字体';">：</span></p>
                    </div>
                </div>

                <!-- Unnamed (形状) -->
                <div id="u123" class="ax_形状">
                    <!-- Unnamed () -->
                    <div id="u124" class="text">
                        <input id="bzms" style="width:407px;height:49px;margin-top:-15px;"  maxlength="64" />
                    </div>
                </div>
            </div>
        </div>
    </div>
    <input text="hidden" hidden="true" id="sjbzid"  />
    <input text="hidden" hidden="true" id="status"  />
    <vs:tree id="tree1" treeLoadUrl="xqfx/init.action" treeAutoLoadUrl="xqfx/open.action" isShowContextMenu="true" menuLoadUrl="document/webui/tree/example/data/contextMenu.xml" height="1000px"/>
</vs:form>
</body>
</html>
<script type="text/javascript">
    setBodyOnLoad(doEventHandler);//注册<body>的onload事件
    function doEventHandler(){
        var t = uiManager.getObject("tree1");
        t.setOnClickHandler(function(id){
            var sjid = t.getParentId(id);
            $("#bzmc").attr({"readonly":true});
            $("#bzms").attr({"readonly":true});
            $("#sjbzmc").attr({"readonly":true});
            document.getElementById("sjbzid").value=sjid;
            document.getElementById("sjbzmc").value=t.getNodeText(sjid);
            document.getElementById("bzmc").value=t.getSelectedNodeText();
            document.getElementById("bzms").value=t.getUserData(id, "created");
            document.getElementById("status").value="chakan";
        })
    }
</script>
<script type="text/javascript">

    //注册<body>的onload事件
    setBodyOnLoad(init);
    function init(){
        var t = uiManager.getObject("tree1");
        var menu = t.getContextMenu();
        menu.addEventListener("addNode",function(id){
            var t = uiManager.getObject("tree1");
            $("#bzmc").attr({"readonly":false});
            $("#bzms").attr({"readonly":false});
            document.getElementById("sjbzid").value=id;
            document.getElementById("sjbzmc").value=t.getSelectedNodeText();
            document.getElementById("status").value="add";
            document.getElementById("bzmc").value='';
            document.getElementById("bzms").value='';
        });

        menu.addEventListener("deleteNode",function(id){
            if("shbz"==id){
                alert("根节点不允许删除，只能重命名！");
                return;
            }
            if(confirm("确定删除吗!")){
                $.ajax({
                    type: "POST",
                    url: "<%=basePath %>/xqfx/deletXqfx.action",
                    data: "id="+id,
                    success: function(data){
                        var obj = JSON.parse(data);
                        if(obj.success){
                            //eaf.alert('信息', '删除成功。');
                            alert("删除成功");
                            var t = uiManager.getObject("tree1");
                            t.reload();
                        }else{
                            //eaf.alert('信息','删除失败！');
                            alert("删除失败！");
                        }
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown){
                        //eaf.alert('警告',errorThrown);
                        alert(errorThrown);
                    }
                });
            }else{

            }
        });

        menu.addEventListener("nodeRename",function(id){
            var t = uiManager.getObject("tree1");

            var sjid = t.getParentId(id);//上级id
            $("#bzmc").attr({"readonly":false});
            $("#bzms").attr({"readonly":false});
            document.getElementById("sjbzid").value=id;
            document.getElementById("sjbzmc").value=t.getNodeText(sjid);
            document.getElementById("bzmc").value=t.getSelectedNodeText();
            document.getElementById("bzms").value=t.getUserData(id, "created");
            document.getElementById("status").value="update";
        });
        //上移下移只操作order_number排序值 ，不改变上下级关系
        //左移右移改变上下级关系
        menu.addEventListener("nodeMoveUp",function(id){

            var t = uiManager.getObject("tree1");
            t.moveUp(id);
            //上级id
            var sjid = t.getParentId(id);
            //移动前排序值
            var pxz = t.getUserData(id, "book");
            $.ajax({
                type: "POST",
                url: "<%=basePath %>/xqfx/MoveUp.action",
                data: "id="+id+"&pxz="+pxz+"&sjid="+sjid,
                success: function(data){
                },
            });
            var t = uiManager.getObject("tree1");
            t.reload();
            return true;//返回值false，则终止节点移动
        });
        //下移
        menu.addEventListener("nodeMoveDown",function(id){
            var t = uiManager.getObject("tree1");
            t.moveDown(id);
            var sjid = t.getParentId(id);
            var pxz = t.getUserData(id, "book");
            $.ajax({
                type: "POST",
                url: "<%=basePath %>/xqfx/MoveDown.action",
                data: "id="+id+"&pxz="+pxz+"&sjid="+sjid,
                success: function(data){

                },
            });
            var t = uiManager.getObject("tree1");
            t.reload();
            return true;//返回值false，则终止节点移动
        });
        //左移，1.移动完毕获取父节点的id，根据父节点的id查询排序值最大的那个，
        //      2.根据最大的排序值+1就是左移之后的排序值
        //		 3.修改操作节点的父节点id
        menu.addEventListener("nodeMoveLeft",function(id){
            var t = uiManager.getObject("tree1");
            t.moveLeft(id);
            //上级id
            var sjid = t.getParentId(id);
            //var pxz = t.getUserData(id, "book");
            //  alert(sjid);
            //alert(pxz);
            $.ajax({
                type: "POST",
                url: "<%=basePath %>/xqfx/Move_L_R.action",
                data: "id="+id+"&sjid="+sjid,
                success: function(data){

                },
            });
            var t = uiManager.getObject("tree1");
            t.reload();
            return true;//返回值false，则终止节点移动
        });
        //右移， 1.移动完毕获取父节点的id，根据父节点的id查询排序值最大的那个，
        //       2.根据最大的排序值+1就是左移之后的排序值
        //		 3.修改操作节点的父节点id
        menu.addEventListener("nodeMoveRight",function(id){
            var t = uiManager.getObject("tree1");
            t.moveRight(id);
            var sjid = t.getParentId(id);
            //alert(sjid);
            $.ajax({
                type: "POST",
                url: "<%=basePath %>/xqfx/Move_L_R.action",
                data: "id="+id+"&sjid="+sjid,
                success: function(data){

                },
            });
            var t = uiManager.getObject("tree1");
            t.reload();
            return true;//返回值false，则终止节点移动
        });

    }

</script>
<script>
    function addBzxqfx(){

        var bzid = $("#sjbzid").val();
        var bzmc = $("#bzmc").val();
        var bzms = $("#bzms").val();
        var status = $("#status").val();
        if(""==bzid){
            alert("请选择上级分类！");
            return;
        }
        if(""==bzmc){
            alert("标准分类名称不能为空！");
            return;
        }
        if("chakan"==status){
            alert("处于查看状态不能保存数据！");
            return;
        }
        $.ajax({
            type: "POST",
            url: "<%=basePath %>/xqfx/saveXqfx.action",
            data: "id="+bzid+"&bzmc="+bzmc+"&bzms="+bzms+"&status="+status,
            success: function(data){
                var obj = JSON.parse(data);
                if(obj.success){
                    //eaf.alert('信息', '保存成功。');
                    alert("保存成功。");
                    var t = uiManager.getObject("tree1");
                    t.reload();
                    document.getElementById("sjbzmc").value='';
                    document.getElementById("bzmc").value='';
                    document.getElementById("bzms").value='';
                }else{
                    //eaf.alert('信息','保存失败！');
                    alert("保存失败！");
                }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown){
                //eaf.alert('警告',errorThrown);
                alert(errorThrown);
            }
        });
    }
</script>
